import type {
  FormItem,
  SelectProps,
  InputInstance,
  SelectInstance,
  TableInstance
} from '@arco-design/web-vue'
import type { TableProps } from '@arco-design/web-vue/es/table/interface'

interface FieldPropsMap {
  Input: InputInstance['$props']
  Select: SelectInstance['$props']
}

type FieldPropsType = keyof FieldPropsMap

interface SearchField<T extends FieldPropsType> {
  type: T
  fieldName: string
  fieldLabel?: string
  formItemProps?: typeof FormItem
  props?: FieldPropsMap[T]
}

type InputType = SearchField<'Input'>
type SelectType = SearchField<'Select'>

interface FieldTypeMap {
  Input: InputType
  Select: SelectType
}

export type FieldTypes = keyof FieldTypeMap // 'Input' | 'Select'

// 当 T 是一个联合类型，这里会采用分布式的方式，比如：InputType | SelectType
export type SearchFields<T extends FieldTypes> = FieldTypeMap[T]

export type SearchFieldTypes = SearchFields<FieldTypes>[]

export interface SchemaSearchFieldProps {
  fields: SearchFieldTypes
  isSyncQueryString?: boolean // 是否将查询参数同步到路由
  resetBtnShow?: boolean // 是否展示重置按钮
}

export type DoSearch = (
  count: number,
  size: number,
  condition: any
) => Promise<{
  data: any
  total: number
}>

export interface SchemaSearchPageProps {
  searchFields?: SearchFieldTypes
  isSyncQueryString?: boolean // 是否将查询参数同步到路由
  resetBtnShow?: boolean // 是否展示重置按钮
  columns: {
    title: string
    dataIndex: string
  }[]
  doSearch: DoSearch
  table?: TableInstance['$props']
}
